package com.qiantu.phone.widget;

import android.content.Context;

import com.qiantu.api.db.LLDeviceDBManager;
import com.qiantu.phone.R;
import com.qiantu.phone.ui.uiutil.LLDeviceUtil;


/**
 * Created by rtyui on 2018/4/28.
 * <p>
 * 效果：ScrollView头部底部弹性
 * <p>
 * tip0:弹性尺寸为 move/2
 * <p>
 * tip1:可以双指同时拉动 这时候执行的事件 只有 一次down 一次up
 * <p>
 * tip2:可以在动画回弹时继续拉动
 * <p>
 * tip3:可以在滑动屏幕的过程中不用抬起直接拉动
 */


public class HomeDeviceView extends HomeDeviceBaseView {

    public HomeDeviceView(Context context) {
        super(context, null);
    }

    public HomeDeviceView(Context context, int type) {
        super(context, type);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.home_device_item;
    }

    protected void initView(){
        super.initView();
        tvOffline.setText(R.string.offline);
    }

    @Override
    protected void onSwitchOperationSucceed(boolean isOpen) {
        mDevice.setIsOpen(isOpen);
        LLDeviceDBManager.getInstance(getContext()).put(mDevice);
        updateView();
    }

    protected void updateView(){
        super.updateView();
        if(mDevice.getIsEnvironment() == 0){
            tvValue.setText(LLDeviceUtil.getDeviceValue(mDevice));
        }else{
            tvValue.setText(LLDeviceUtil.getEnviromentData(mDevice) + LLDeviceUtil.getEnviromentUnit(mDevice));
        }
    }
}
